// let BASEURL='http://www.mryang.fun/';
let BASEURL='https://www.mryang.fun/';

export const Request=(option)=>{
  return new Promise((resolve,reject)=>{
      uni.request({
        url: BASEURL+option.url,
        method:option.method,
        data:option.data==undefined?'':option.data,
        header:{"Authorization":'Bearer '+' '+ uni.getStorageSync('token')},
        success(res){
          if(res.statusCode==401){
			  uni.showToast({
			    title: '请重新登录',
			    duration:1000,
			  	icon:"none"
			  });
			  console.log(uni.getStorageSync("appid","401拦截失效时id"));
			  uni.removeStorageSync("user");
			  uni.removeStorageSync("token");
			  uni.removeStorageSync("appid");
            uni.reLaunch({
             url:"/pages/login/login"
            })
            return
          }
            resolve(res.data)
        },
        fail(err) {
          console.log(err, BASEURL+option.url,"utils-pages");
          //请求失败
          resolve({code:-500,message:'运行时错误,请稍后再试,或联系客服处理'})
        }
      })
  })
}
